package com.example.thridhero.webchatfragment;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

public class FriendChat extends AppCompatActivity {
    private static List<Content> contentList;

    public static void onActionStart(Context content, Friends friends){
        Intent intent = new Intent(content,FriendChat.class);
        intent.putExtra("position",friends);
        contentList = friends.getContent();
        content.startActivity(intent);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_friend_chat);

        final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.chat_content_list);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(linearLayoutManager);
        final FriendChatAdapter friendChatAdapter = new FriendChatAdapter(contentList);
        recyclerView.setAdapter(friendChatAdapter);

        Button sendButton = (Button) findViewById(R.id.sendButton);
        final TextView sendText = (TextView) findViewById(R.id.edit_text);

        sendButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String text = sendText.getText().toString();
                Content content = new Content();
                content.setSendType(Content.MESSAGE_SEND);
                content.setContent(text);
                contentList.add(content);
                friendChatAdapter.notifyItemInserted(contentList.size()-1);
                recyclerView.scrollToPosition(contentList.size()-1);
                sendText.setText("");
            }
        });


    }

    public static List<Content> getContentList() {
        return contentList;
    }

    public static void setContentList(List<Content> contentList) {
        FriendChat.contentList = contentList;
    }
}
